package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.BlackListMapper;
import com.tanhua.dubbo.mappers.UserInfoMapper;
import com.tanhua.model.db.BlackList;
import com.tanhua.model.db.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * select * from tb_user_info where id in (
     * 	SELECT black_user_id FROM tb_black_list where user_id=106
     * )
     *
     * 没有配置分页插件
     */
    @Override
    public IPage<UserInfo> findByUserId(Long userId, Integer page, Integer pagesize) {
        //构造分页的参数对象Page（当前页和每页条数）
        Page<UserInfo> pageParm = new Page<>(page,pagesize);
        return userInfoMapper.findBlackList(pageParm,userId);
    }

    //根据userId和blackUserId删除
    //delete from tb_black_list where user_id=106 and black_user_id=1
    public void delete(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        qw.eq("black_user_id",blackUserId);
        blackListMapper.delete(qw);
    }
}
